package com.example.demo.dao;

import com.example.demo.pojo.Department;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.HashMap;
@Repository
public class DepartmentDao {
    private static HashMap<Integer, Department> departments=null;
    static {
        departments=new HashMap<Integer, Department>();
        departments.put(101,new Department(101,"巴黎圣日耳曼"));
        departments.put(102,new Department(102,"巴萨罗那"));
        departments.put(103,new Department(103,"曼城"));
        departments.put(104,new Department(104,"拜仁慕尼黑"));
        departments.put(105,new Department(105,"皇家马德里"));
    }

    int iid=105;
//获取全部俱乐部
    public Collection<Department> getDepartment(){
        return departments.values();
    }

    public void save(Department department){
        if(department.getId()==null){
            department.setId(iid++);
            departments.put(department.getId(),department);
        }
    }

//    通过Id获取俱乐部
    public Department query(Integer id){
        return departments.get(id);
    }
}
